package net.hpxn.gsmc.core.event;

import net.hpxn.gsmc.core.server.GameType;
import net.hpxn.gsmc.core.server.Server;

public class EventFactory {
	private static volatile EventFactory INSTANCE;

	public static EventFactory getInstance() {
		if ( INSTANCE == null ) {
			synchronized ( EventFactory.class ) {
				if ( INSTANCE == null ) {
					INSTANCE = new EventFactory();
				}
			}
		}
		return INSTANCE;
	}

	public static BaseEvent createEvent( String pRawEvent, Server pServer )
			throws IllegalArgumentException {
		try {
			switch ( GameType.valueOf( pServer.getServerConfig().getType()
					.toUpperCase() ) ) {
			case TF2:
				return new TF2Event( pRawEvent, pServer );
			case L4D:
				return new L4DEvent( pRawEvent, pServer );
			case L4D2:
				return new L4D2Event( pRawEvent, pServer );
			default:
				return null;
			}
		} catch ( IllegalArgumentException e ) {
			throw new IllegalArgumentException( "No such game type." );
		}
	}
}
